
<?php require_once WEB_ROOT_FOLDER."views/header.php";?>
<?php
if(isset($_SESSION['access_level']) && isset($_SESSION['username']) && ($_SESSION['access_level'] > 8)){
    ?>
<fieldset class="col_12 column">
    <legend class="col_12 column">Tutaj możesz przypisać rolę w firmie do użytkownika. Ciekawa rzecz, prawda?</legend>
    <?php
    if(isset($data['page']['rule']) && is_array($data['page']['rule']) && isset($data['page']['account']) && is_array($data['page']['account'])){
        ?>
    <h4>Przypisz rolę do użytkownika</h4>
    <table class="tight" cellpadding="0" cellspacing="0">
        <thead>
            <tr class="alt firts last">
                <td class="col_4 column" value="username" rel="0">
                    Nazwa użytkownika
                </td>
                <td class="col_4 column" value="user_rule" rel="1">
                    Rola w firmie
                </td>
                <td class="col_4 column" value="action" rel="2">
                    Dostępne akcje
                </td>
            </tr>
        </thead>
        <tbody>
            <?php
            foreach($data['page']['account'] as $key => $value){
                ?>
        <form method="post" action="<?php echo SITE_ROOT;?>przypisz-role/aktualizuj-role.html">
            <?php
            if(isset($data['page']['csrf_token'])){
                ?>
            <input type="hidden" name="csrf_token" value="<?php echo $data['page']['csrf_token'];?>">
            <?php
            }
            ?>
            <?php
            if(isset($value['0'])){
                ?>
            <input type="hidden" name="username" value="<?php echo $value['0'];?>"> 
            <?php
            }
            ?>
                <tr class="">
                    <td class="col_4 column" value="<?php echo $value['0'];?>">
                        <?php echo $value['0'];?>
                    </td>
                    <td class="col_4 column">
                        <select class="col_12 column" name="rule_name" required autofocus>
                            <?php
                            if(!isset($data['page']['user_rule']['0']['0']) && !isset($data['page']['user_rule']['0']['1'])){
                                ?>
                            <option selected="selected">Wybierz rolę w organizacji</option>
                            <?php
                            }
                            ?>
                            <?php
                            foreach($data['page']['rule'] as $key => $value){
                                if($value['0'] == $data['page']['user_rule']['0']['1']){
                                    ?>
                            <option value="<?php echo $value['0'];?>" selected="selected"><?php echo $value['0'];?></option>
                            <?php
                                }
                                else {
                                 ?>
                            <option value="<?php echo $value['0'];?>"><?php echo $value['0'];?></option>
                            <?php
                                }
                            }
                            ?>
                        </select>
                    </td>
                    <td class="col_4 column" value="">
                        <input type="submit" value="Przypisz nową rolę" name="submit" id="submit">
                    </td>
                </tr>
        </form>
            <?php
            }
            ?>
        </tbody>
    </table>
    <?php
    }
    ?>
</fieldset>
<?php
}
?>
<?php require_once WEB_ROOT_FOLDER."views/footer.php";?>
